package Ep02_LinkedList._0203;

import Ep02_LinkedList.ListNode;

/**
 * @author Jimmy
 * @date 2023/3/5 - 23:50
 * 说明: 力扣 0203 删除链表节点  方法一：不使用虚拟头结点dummy，使用临时指针cur
 */
public class DeleteWithoutDummy {

    public ListNode removeElements(ListNode head, int val){
        ListNode cur = head;
        while(head != null && head.val == val){
            head = head.next;
        }
        while(cur != null && cur.next != null){
            if (cur.next.val == val){
                cur.next = cur.next.next;
            } else {
                cur = cur.next;
            }
        }
        return head;
    }
}


